const { default: axios } = require("axios");
const { dewuHeaders } = require("../../tools");
const sign = require("../../tools/sign");

/**
 *  Dewu-API获取当前Trending鞋子列表
 * @param {import("koa").Context} ctx  - 路由上下文
 *  */
module.exports = async(ctx) => {
    let { pageNum, pageSize } = ctx.request.query;

    const signId = sign({
        tabId: 4,
        limit: pageSize || 20,
        lastId: '',
    })
    const response = await axios.post(
        'https://app.dewu.com/api/v1/h5/index/fire/shopping-tab', {
            sign: signId,
            tabId: 4,
            limit: 20,
            lastId: '',
        }, {
            headers: dewuHeaders(),
        });
    const result = response.data.data
    if (result.list) {
        const productList = result.list.map((item) => {
            return {
                ...item.product,
                minSalePrice: item.product.price,
            }
        })
        result.productList = productList
    }
    ctx.body = result
}